import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    sid: '',
    isLogin: false,
    token: '',
    userInfo: {}
  },
  mutations: {
    setSid (state, val) {
      state.sid = val
    },
    setToken (state, val) {
      state.token = val
      localStorage.setItem('token', val)
    },
    // 设置用户的基本信息
    setUserInfo (state, value) {
      if (value === '') return
      state.userInfo = value
      if (value) {
        localStorage.setItem('userInfo', JSON.stringify(value))
      }
    },
    // 设置登录状态
    setIsLogin (state, val) {
      state.isLogin = val
    }
  },
  actions: {
  },
  modules: {
  }
})
